import 'package:azlistview/azlistview.dart';

class IMGroupResponse {
  String msg;
  List<GroupModel> data;

  IMGroupResponse({this.msg, this.data});

  IMGroupResponse.fromJson(Map<String, dynamic> json) {
    msg = json['msg'];
    if (json['data'] != null) {
      data = new List<GroupModel>();
      json['data'].forEach((v) {
        data.add(new GroupModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['msg'] = this.msg;
    if (this.data != null) {
      data['data'] = this.data.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class GroupModel {
  int id;
  String friendgroup;
  int sort;
  List<FriendModel> friend;

  GroupModel({this.id, this.friendgroup, this.friend, this.sort});

  GroupModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    friendgroup = json['name'];
    sort = json['sort'];
    if (json['friend'] != null) {
      friend = new List<FriendModel>();
      json['friend'].forEach((v) {
        friend.add(new FriendModel.fromJson(v));
      });
    } else {
      friend = []; // 防止为空报错
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.friendgroup;
    data['sort'] = this.sort;
    if (this.friend != null) {
      data['friend'] = this.friend.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class FriendModel extends ISuspensionBean {
  String username;
  String mobile;
  String schoolname;
  String bio;
  String avatar;

  String tagIndex; // 分组用
  String namePinyin;// 分组

  String followRemark;

  String get remarkname {
    if(username == null && followRemark == null) return mobile;
    return followRemark == null ? username : followRemark;
  }

  FriendModel({this.username, this.mobile, this.schoolname, this.bio, this.avatar});

  FriendModel.fromJson(Map<String, dynamic> json) {
    username = json['username'];
    mobile = json['mobile'];
    schoolname = json['schoolname'];
    bio = json['bio'];
    avatar = json['avatar'];
    followRemark = json["follow_remark"];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['username'] = this.username;
    data['mobile'] = this.mobile;
    data['schoolname'] = this.schoolname;
    data['bio'] = this.bio;
    data['avatar'] = this.avatar;
    return data;
  }

  @override
  String getSuspensionTag() => tagIndex;
}